package irri.soils.ssnm;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.TextView;

public class ActivityC extends SSNM implements View.OnClickListener{
	
	private int option = 0;
	private View button1;
	private RadioButton radio1;
	private RadioButton radio2;
	private RadioButton radio3;
	private Bundle b;
	private TextView question;

	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.c);
        setCustomTitle();
        
        
        radio1 = (RadioButton) findViewById(R.id.radio1);
        radio1.setOnClickListener(this);
        radio2 = (RadioButton) findViewById(R.id.radio2);
        radio2.setOnClickListener(this);
        radio3 = (RadioButton) findViewById(R.id.radio3);
        radio3.setOnClickListener(this);
        button1 = (Button) findViewById(R.id.button1);
        button1.setOnClickListener(this);
        button1.setEnabled(false);
                
        b = this.getIntent().getExtras();
        question = (TextView) findViewById(R.id.question);
        question.setText(get("crop0"));
        radio1.setText(get("crop1"));
        radio2.setText(get("crop2"));
        radio3.setText(get("crop3"));
        if(b.containsKey("crop")){
	        switch(b.getInt("crop")){
	        case 1: radio1.performClick(); break;
	        case 2: radio2.performClick(); break;
	        case 3: radio3.performClick(); break;
	        }
        }
    }
    
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		if(radio1.isChecked()) radio1.performClick();
		if(radio2.isChecked()) radio2.performClick();
		if(radio3.isChecked()) radio3.performClick();
	}

	@Override
	public void onClick(View v) {
		switch(v.getId()){
		case R.id.radio1: option = 1; button1.setEnabled(true); break;
		case R.id.radio2: option = 2; button1.setEnabled(true); break;
		case R.id.radio3: option = 3; button1.setEnabled(true); break;
		case R.id.button1:
			Intent intent = new Intent(ActivityC.this, ActivityD.class);
			b.putInt("crop", option);
			if(option==1) b.remove("cav2");
			intent.putExtras(b);
			startActivity(intent);
			finish();
			break;
		}
	}

	@Override
	public void onBackPressed() {
		Intent intent = new Intent(ActivityC.this, ActivityZ.class);
		intent.putExtras(b);
		startActivity(intent);
		finish();
	}
}